/**
 * 
 */
package com.oolong.account.web;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.oolong.account.dal.InitemDAO;
import com.oolong.account.dal.data.Initem;
import com.oolong.account.model.UserModel;
import com.oolong.account.service.InManage;

/**
 * @author oolong
 * 
 */
// 标记它是个SPRING的BEAN，是MVC里的C
@Controller
// 表示这个类就是reqOutItem.do
@RequestMapping("/deleteInItem.do")
public class InItemDeleteController {
	Logger logger = Logger.getLogger(InItemDeleteController.class);
	// 表示需要SPRING自动注入
	@Autowired
	private InManage inManage;
	@Autowired
	InitemDAO initemDAO;
	String message = " ";

	@RequestMapping(method = RequestMethod.GET)
	public String processOutItem(@RequestParam("inid") int inid,
			ModelMap model, HttpServletResponse response, HttpSession session) {
		UserModel userModel = (UserModel) session.getAttribute("user");
		Initem initem = initemDAO.selectByPrimaryKey(inid);
		if (initem != null) {
			if (userModel.getId() != initem.getUserId()) {
				message = "你无权删除该记录：" + inid;
			} else {
				boolean deleteresult = inManage.delete(inid);
				if (deleteresult == true) {
					message = "成功删除支出项，id为：" + inid;
				} else {
					message = "删除支出项失败，id为：" + inid;
				}
			}
		} else {
			message = "你无权删除该记录：" + inid;
		}
		model.addAttribute("message", message);
		response.setContentType("text/html;charset=UTF-8");
		return "deleteOutItem";
	}
}
